package com.rabbiter.cm.domain;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 表示系统资源，通常用于菜单或权限管理。
 * 可以表示菜单项、功能模块等，并支持层级结构（父-子关系）。
 */
public class SysResource implements Serializable {

    /**
     * 序列化版本唯一标识符，确保类的版本一致性。
     */
    private static final Long serialVersionUID = 1L;

    /**
     * 资源的唯一标识 ID。
     */
    private Long id;

    /**
     * 资源名称，不能为空。
     * 使用 @NotBlank 注解进行非空校验，为空时会提示“菜单名称不能为空”。
     */
    @NotBlank(message = "菜单名称不能为空")
    private String name;

    /**
     * 资源路径，通常是前端路由地址或接口路径。
     */
    private String path;

    /**
     * 菜单权限等级，用于表示菜单在树形结构中的层级。
     */
    private Integer level;

    /**
     * 父资源的 ID，用于构建父子层级关系。
     */
    private Long parentId;

    /**
     * 父资源对象，用于构建双向关联的树形结构。
     */
    private SysResource parent;

    /**
     * 子资源列表，表示该资源下的所有子资源。
     */
    private List<SysResource> children;


    /**
     * 默认构造函数，用于创建一个空的 SysResource 对象。
     */
    public SysResource() {
    }

    /**
     * 带参数的构造函数，用于初始化所有字段。
     *
     * @param id         资源的唯一标识 ID
     * @param name       资源名称
     * @param path       资源路径
     * @param level      权限等级
     * @param parentId   父资源 ID
     * @param parent     父资源对象
     * @param children   子资源列表
     */
    public SysResource(Long id, String name, String path, Integer level, Long parentId, SysResource parent, List<SysResource> children) {
        this.id = id;
        this.name = name;
        this.path = path;
        this.level = level;
        this.parentId = parentId;
        this.parent = parent;
        this.children = children;
    }

    // Getter 和 Setter 方法

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public SysResource getParent() {
        return parent;
    }

    public void setParent(SysResource parent) {
        this.parent = parent;
    }

    public List<SysResource> getChildren() {
        return children;
    }

    public void setChildren(List<SysResource> children) {
        this.children = children;
    }

    /**
     * 判断当前对象是否与另一个对象相等。
     * 根据所有字段判断两个对象是否相同。
     *
     * @param o 要比较的对象
     * @return 如果对象相等则返回 true，否则返回 false
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SysResource that = (SysResource) o;
        return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(path, that.path) && Objects.equals(level, that.level) && Objects.equals(parentId, that.parentId) && Objects.equals(parent, that.parent) && Objects.equals(children, that.children);
    }

    /**
     * 生成基于所有字段的哈希码。
     *
     * @return 返回哈希码值
     */
    @Override
    public int hashCode() {
        return Objects.hash(id, name, path, level, parentId, parent, children);
    }

    /**
     * 返回当前对象的字符串表示，用于调试和日志输出。
     *
     * @return 包含所有字段信息的字符串
     */
    @Override
    public String toString() {
        return "SysResource{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", level=" + level +
                ", parentId=" + parentId +
                ", parent=" + parent +
                ", children=" + children +
                '}';
    }
}
package com.rabbiter.cm.domain;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

public class SysResource implements Serializable {

    private static final Long serialVersionUID = 1L;

    private Long id;

    @NotBlank(message = "菜单名称不能为空")
    private String name;

    private String path;

    //菜单权限等级
    private Integer level;

    private Long parentId;

    //父菜单
    private SysResource parent;

    //子菜单
    private List<SysResource> children;

    public SysResource() {
    }

    public SysResource(Long id, String name, String path, Integer level, Long parentId, SysResource parent, List<SysResource> children) {
        this.id = id;
        this.name = name;
        this.path = path;
        this.level = level;
        this.parentId = parentId;
        this.parent = parent;
        this.children = children;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public SysResource getParent() {
        return parent;
    }

    public void setParent(SysResource parent) {
        this.parent = parent;
    }

    public List<SysResource> getChildren() {
        return children;
    }

    public void setChildren(List<SysResource> children) {
        this.children = children;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SysResource that = (SysResource) o;
        return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(path, that.path) && Objects.equals(level, that.level) && Objects.equals(parentId, that.parentId) && Objects.equals(parent, that.parent) && Objects.equals(children, that.children);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, path, level, parentId, parent, children);
    }

    @Override
    public String toString() {
        return "SysResource{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", level=" + level +
                ", parentId=" + parentId +
                ", parent=" + parent +
                ", children=" + children +
                '}';
    }
}
